package com.smartens.boit.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.smartens.boit.R;
import com.smartens.boit.bean.DevicesList;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 离线设备适配器
 * @Author songtt
 * @Date 2021/3/4
 */

public class AbnormalAdapter extends RecyclerView.Adapter<AbnormalAdapter.ViewHolder>{
    private List<DevicesList> mList;

    public AbnormalAdapter(List<DevicesList> list) {
        mList = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //将我们自定义的item布局R.layout.item_one转换为View
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_abnormal, parent, false);
        //将view传递给我们自定义的ViewHolder
        ViewHolder holder = new ViewHolder(view);
        //返回这个MyHolder实体
        return holder;
    }

    /**
     * 通过方法提供的ViewHolder，将数据绑定到ViewHolder中
     * @param holder
     * @param position
     */
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.textView.setText(mList.get(position).getDevicesName());
        holder.number.setText("设备编号："+ mList.get(position).getDevicesNum());


    }

    /**
     * 获取数据源总的条数
     * @return
     */
    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        TextView number;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.name);
            number = itemView.findViewById(R.id.number);
        }
    }

    public void getData(List<DevicesList> lists){
        mList = lists;
    }

}
